package code.android.MiracleWalker.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.util.List;

import javax.crypto.spec.DESedeKeySpec;

import sunn.android.IO.AnFile;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.util.Log;

public class MiracleWalkerAlbumGenerator {
	
	String mSdcardPath = null;
	Context mContext = null;
	AssetManager mAssetManager = null;
	
	public MiracleWalkerAlbumGenerator(Context context, String path) {
		mSdcardPath = path;
		mContext = context;
	}
	
	public void generate() {
		
	}
	
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
	}
	
	public String[] getFileNamesFromAssets(String assetsFolderName) {
		mAssetManager = mContext.getResources().getAssets();
		String[] fileNames = null; 
		
		try {
			fileNames = mAssetManager.list(assetsFolderName);
		} catch (IOException e) {
		}
		
		if(fileNames.length == 0 && fileNames == null){
			return null;
		}
		
		return fileNames;
	}

	public void copyAssetsFileToSdCard(String assetsFolderName, String fileName) {
		mAssetManager = mContext.getResources().getAssets();
		
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		
		try {
			bis = new BufferedInputStream(mAssetManager.open(assetsFolderName+File.separator+fileName));
			bos = new BufferedOutputStream(new FileOutputStream(mSdcardPath+fileName));
			
			int bytesRead = 0;
			byte[] buffer = new byte[1024];
			
			while ((bytesRead = bis.read(buffer, 0, 1024)) != -1) {
			    bos.write(buffer, 0, bytesRead);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
			bis.close();
			bos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	
	
	
}
